// pages/craftsman_index/craftsman_index.js
const config = require('../../config.js');
const utils = require('../../utils/util.js');
const request = require('../../utils/request.js')
import {  getWorkDetail } from '../../static/api/api.js'
let app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        otherImgArr:[],
        indicatorDots: true,
        autoplay: true,
        interval: 3000,
        duration: 1000,
        goodsData:null,
        viewType:'detail'
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            'goodsId': options.id
        })
        let that = this;
        app.getUserInfo(function (data) {
            that.setData({
                memberInfo: data
            })
            that.getWorkDetail()
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        
        
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    //获取项目详情
    getWorkDetail() {
        let that = this;
        wx.showLoading({
            title: '加载中',
        })
        getWorkDetail({ goods_id: this.data.goodsId }).then(response => {
            wx.hideLoading()
            console.log(response.data)
            that.setData({
                'goodsData': response.data.info,
                'otherImgArr': utils.formatImgArr(response.data.info.other_imgs)
            })
        }).catch(response => {
            wx.hideLoading()
            console.log(response)
        })
    },
    changeViewType(e){
        let dataset = e.currentTarget.dataset;
        this.setData({
            viewType:dataset.type
        })
    },
    //预览图片
    handleImagePreview(e) {
        const idx = e.target.dataset.index
        const images = this.data.otherImgArr
        wx.previewImage({
            current: images[idx], //当前预览的图片
            urls: images, //所有要预览的图片
        })
    },
})